/*
 * File:   FollowReward.cpp
 * Author: Hadrien
 *
 * Created on 12 juillet 2012, 00:16
 */

#include "FollowReward.h"

FollowReward::FollowReward() {
}

FollowReward::~FollowReward() {
}

double FollowReward::operator()(const FollowState state, const FollowAction& a) const {
    //USE MANATHAN DISTANCE
	FollowState::States s = state.getValue();

	//Move agent. Agent remains in center
	if (a.getValue() == FollowAction::North)
		s.posY--;
	else if (a.getValue() == FollowAction::East)
		s.posX--;
	else if (a.getValue() == FollowAction::South)
		s.posY++;
	else if (a.getValue() == FollowAction::West)
		s.posX++;

	int dist = abs(s.posX) + abs (s.posY);

	if(dist >= 3)
	{
		return -20;
	}
	else if(dist >= 2)
	{
		return -1;
	}
	else if(dist >= 1)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}
